package com.kzd.gtgame.main.access

import androidx.core.widget.addTextChangedListener
import com.kzd.gtgame.R
import com.kzd.gtgame.custom.setOnClickAntiShakeListener
import com.kzd.gtgame.jetpack.vm.AccessViewModel
import com.module.lemlin.owner.OwnerViewModeFragment
import kotlinx.android.synthetic.main.fragment_access_pwd_change.*

class AccessPwdChangeFragment : OwnerViewModeFragment<AccessViewModel>() {

    companion object {
        fun newInstance(): AccessPwdChangeFragment {
            return AccessPwdChangeFragment()
        }
    }

    override fun viewModel(): AccessViewModel {
        return createViewModel(requireActivity())
    }

    override val layoutResId: Int
        get() = R.layout.fragment_access_pwd_change

    override fun initView() {
        etAccessPwdChangeOld.addTextChangedListener {
            tvAccessPwdChangeSubmit.isEnabled = !it.isNullOrEmpty() &&
                    !etAccessPwdChangeNew.text.isNullOrEmpty() &&
                    !etAccessPwdChangeNewSure.text.isNullOrEmpty()
        }
        etAccessPwdChangeNew.addTextChangedListener {
            tvAccessPwdChangeSubmit.isEnabled = !it.isNullOrEmpty() &&
                    !etAccessPwdChangeOld.text.isNullOrEmpty() &&
                    !etAccessPwdChangeNewSure.text.isNullOrEmpty()
        }
        etAccessPwdChangeNewSure.addTextChangedListener {
            tvAccessPwdChangeSubmit.isEnabled = !it.isNullOrEmpty() &&
                    !etAccessPwdChangeOld.text.isNullOrEmpty() &&
                    !etAccessPwdChangeNew.text.isNullOrEmpty()
        }
        tvAccessPwdChangeSubmit.setOnClickAntiShakeListener {
            viewModel.accessChangePwd(
                etAccessPwdChangeOld.text.toString(),
                etAccessPwdChangeNew.text.toString(),
                etAccessPwdChangeNewSure.text.toString()
            )
        }
    }

    override fun initViewMode() {

    }


}